import type { ListResponse, PageRequest } from "@/types/common";
import type {
  RoleItem,
  RoleDetail,
  TreeList,
  UserItem,
  AddRoleParams,
  EditRoleParams
} from "@/types/system";
import { request } from "@/utils/reuqest";

/**
 * 获取角色列表
 */
export const getRoleListAPI = () => {
  return request<RoleItem[]>("/park/sys/role");
};

/**
 * 获取所有功能权限(树形)
 */
export const getTreeListAPI = () => {
  return request<TreeList[]>("/park/sys/permision/all/tree");
};

/**
 * 查询当前角色详情-权限和分配人数
 */
export const getRoleDetailAPI = (roleId: number) => {
  return request<RoleDetail>(`/park/sys/role/${roleId}`);
};

/**
 * 查询角色关联的用户列表
 */
export const getUserListAPI = (roleId: number, params?: PageRequest) => {
  return request<ListResponse<UserItem>>(
    `/park/sys/roleUser/${roleId}`,
    "GET",
    params
  );
};

/**
 * 添加角色
 */
export const addRoleAPI = (params: AddRoleParams) => {
  return request("/park/sys/role", "POST", params);
};

/**
 * 编辑角色
 */
export const editRoleAPI = (params: EditRoleParams) => {
  return request('/park/sys/role', "PUT", params);
};

/**
 * 删除角色
 */
export const deleteRoleAPI = (roleId: number) => {
  return request(`/park/sys/role/${roleId}`, "DELETE");
};